package dem1;

import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-04-01
 * Time: 15:31
 */
public class Test {
    public static void main(String[] args) {
        char[] ch1 = {'A','B','C','D'};
        char[] ch2 = new char[80];
        Random random = new Random();
        HashMap<Character,Integer> hm = new HashMap<>();
        for (int i = 0; i < ch2.length; i++) {
            int n = random.nextInt(4);
            ch2[i] = ch1[n];
            if (hm.containsKey(ch2[i])){
                Integer count = hm.get(ch2[i]);
                count++;
                hm.put(ch2[i],count);
            }else {
                hm.put(ch2[i],1);
            }
        }
        System.out.println(hm);
        int max = 0;
        Set<Map.Entry<Character, Integer>> entries = hm.entrySet();
        for (Map.Entry<Character, Integer> entry : entries) {
            if (max < entry.getValue()){
                max = entry.getValue();
            }
        }
        for (Map.Entry<Character, Integer> entry : entries) {
            if (max == entry.getValue()){
                System.out.println(entry.getKey());
            }
        }

    }
    public static void main1(String[] args) {
        String str = "aaaaadecscfdadeeeeffggbbbbd";
        str = str.replaceAll("(.)\\1+","$1");
        System.out.println(str);

        Map<String,String> map = new HashMap<>();
        map.put("爱莉希雅","雷电芽衣");
        map.put("雷电芽衣","琪亚娜");
        map.put("李素裳","符华");

        HashMap<String,Integer> hm = new HashMap<>();
        hm.put("A",1);
        hm.put("A",2);
        hm.put("B",1);
        System.out.println(hm);

//        boolean String;
//        map.forEach(new BiConsumer<String, String>() {
//            @Override
//            public void accept(String s, String s2) {
//                System.out.println(s + s2);
//            }
//        });

        //Set<Map.Entry<String, String>> entries = map.entrySet();
        //entries.forEach(stringStringEntry ->System.out.println(stringStringEntry.getKey() + "=" + stringStringEntry.getValue()));
        //System.out.println(map);

        //Set<String> set = map.keySet();
        //set.forEach(s ->System.out.println(map.get(s)));

//        for (String s : set) {
//            System.out.println(map.get(s));
//        }


//        Iterator<String> iterator = set.iterator();
//        while (iterator.hasNext()){
//            String value = map.get(iterator.next());
//            System.out.println(value);
//        }

    }
}
